<?php
	function get_media_elements($media_type){
		global $settings;
		$n = "\r\n";		// newline
		$t = "\t";			// tab
		$minify = $settings['minify_media'];
		if(($media_type == 'css') && isset($settings['installed_media'][$media_type])){
			if($minify){
				return($t.'<link rel="stylesheet" type="text/css" media="all" href="'.get_minify_url_by_media_type($media_type).'" />'.$n);
			}else{
				$media_output = '';
				foreach($settings['installed_media'][$media_type] as $media){
					$media_output .= $t.'<link rel="stylesheet" type="text/css" media="all" href="'.$settings['media_directory'].$media_type.'/'.$media.'.'.$media_type.'" />'.$n;
				}
				return($media_output);
			}
		}elseif(($media_type == 'js') && isset($settings['installed_media'][$media_type])){
			if($minify){
				return($t.'<script type="text/javascript" src="'.get_minify_url_by_media_type($media_type).'"></script>'.$n);
			}else{
				$media_output = '';
				foreach($settings['installed_media'][$media_type] as $media){
					$media_output .= $t.'<script type="text/javascript" src="'.$settings['media_directory'].$media_type.'/'.$media.'.'.$media_type.'"></script>'.$n;
				}
				return($media_output);
			}
		}
	}
	
	function get_minify_url_by_media_type($type){
		global $settings;
		$minify_url = '';
		if(isset($settings['installed_media'][$type])){
			$minify_url .= '/'.$settings['module_directory'].'minify.php?files=';
			foreach($settings['installed_media'][$type] as $media){
				$minify_url .= $settings['media_directory'].$type.'/'.$media.'.'.$type;
				if($media != end($settings['installed_media'][$type])){
					$minify_url .= ',';
				}
			}
		}
		return $minify_url;
	}
?>